<?php

namespace app\api\controller\v1\home;

use app\admin\model\DataStoreUser;
use app\api\controller\Api;

class Base extends Api
{

    /**
     * 获取用户信息
     * @return void
     */
    public function get(){
        $list = $this->getModel()->where(['status'=>1])->findOrEmpty();
        if($list->isEmpty())$this->error('商铺不存在或未审核铜过');
        $this->success('获取成功',$list);
    }

    /**
     * 修改商铺信息
     * @return void
     */
    public function set(){
        $rule = [
            'opening_time'    => 'require',
            'store_type'    => 'require',
            'tel'    => 'require',
            'address'    => 'require',
            'lat'    => 'require',
            'lng'    => 'require',
        ];
        $message  =   [
            'opening_time.require' => '开业时间不为空',
            'store_type.require' => '商铺类型不为空',
            'tel.require' => '电话不为空',
            'address.require' => '地址不为空',
            'lat.require' => '纬度不为空',
            'lng.require' => '经度不为空',
        ];
        $this->validate($this->post, $rule,$message);
        $list = $this->getModel()->where(['status'=>1])->findOrEmpty();
        if($list->isEmpty())$this->error('商铺不存在或未审核铜过');
        if($list->save($this->post)){
            $this->success('修改成功',$list);
        }else{
            $this->error('修改失败',$list);
        }

    }


    private function getModel(){
        return DataStoreUser::where(['unid'=>$this->user['id']]);
    }

}